<?php
class BookAction extends HomeAction {
    public function index(){
    	$bookId = isset($_GET["book"])?(int)$_GET["book"]:1;
    	 
    	$Book = D("Book");
    	$bookInfo = $Book->find($bookId);
    	$BookContent = D("BookContent");
    	$lastBookContent = $BookContent->where('bookId='.$bookId)->order('addTime')->find();
    	$catId　=　$bookInfo["catId"];
    	$this->assign("book", $bookInfo);
    	$this->assign("lastContent", $lastBookContent);
    	$this->assign("currentCat", $catId);

    	$weekRank = $Book->where('catId='.$catId)->order('weekClick')->limit(10)->select();
        $this->assign("weekRank",$weekRank);
    	$monthRank = $Book->where('catId='.$catId)->order('monthClick')->limit(10)->select();
        $this->assign("monthRank",$monthRank);
    	$totalRank = $Book->where('catId='.$catId)->order('click')->limit(10)->select();
        $this->assign("totalRank",$totalRank);
    	
    	$this->display();
    }
    
    public function menu(){
    	$bookId = isset($_GET["book"])?(int)$_GET["book"]:1;
    	
    	$Book = D("Book");
    	$bookInfo = $Book->find($bookId);
    	$BookContent = D("BookContent");
    	$bookContentList = $BookContent->where('bookId='.$bookId)->order('id desc')->select();
 	$catId　=　$bookInfo["catId"];
    	$this->assign("book", $bookInfo);
    	$this->assign("contentList", $bookContentList);
    	$this->assign("currentCat", $catId);
    	
    	$this->display();
    }
    
    public function content(){
    	$bookId = isset($_GET["book"])?(int)$_GET["book"]:1;
    	$contentId = isset($_GET["contentId"])?(int)$_GET["contentId"]:1;
    	 
    	$Book = D("Book");
    	$bookInfo = $Book->find($bookId);
    	$BookContent = D("BookContent");
    	$bookContentInfo = $BookContent->find($contentId);
 	$catId　=　$bookInfo["catId"];
    	$this->assign("book", $bookInfo);
    	$this->assign("bookContentInfo", $bookContentInfo);
    	$this->assign("currentCat", $catId);
    	
    	$bookContent = $BookContent->getContent($bookContent);
    	$this->assign("bookContent", $bookContent);
    	
    	$prevContentInfo = $BookContent->where('bookId='.$bookId.' and id<'.$contentId)->order('id desc')->find();
    	$nextContentInfo = $BookContent->where('bookId='.$bookId.' and id>'.$contentId)->order('id asc')->find();
    	$this->assign("prevContentInfo", $prevContentInfo);
    	$this->assign("nextContentInfo", $nextContentInfo);
    	
    	$this->display();
    }
}
